package com.youping.web.controller.demo;

import com.youping.common.utils.FastDFSClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * Date:2019/6/29
 *
 * @author:zrlie
 */
@RequestMapping("/upload")
@Controller
public class FastDfsControllerDemo {

    @ResponseBody
    @PostMapping
    public Map upload(MultipartFile file){
        HashMap<String, String> map = new HashMap<>();
        map.put("data","success");
        try {
// 获取文件拓展名
            String file_ext_name = file.getOriginalFilename().
                    substring(file.getOriginalFilename().lastIndexOf(".")+1);
            FastDFSClient fastDFSClient = new
                    FastDFSClient("classpath:fastdfs/tracker.conf");
            String url = fastDFSClient.uploadFile(file.getBytes(),
                    file_ext_name);
            map.put("url",url);
            return map;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }


    @RequestMapping("/fastDemo")
    public String fastDemo(){
        return "demo/table/fastUploadTest";
    }
}
